package com.ddc.drivers.fmpxml;

public class SearchTerm {
	public static final int EQUALS = 0;
	public static final int GREATER_THAN = 1;
	public static final int GREATER_THAN_OR_EQUALS = 2;
	public static final int LESS_THAN = 3;
	public static final int LESS_THAN_OR_EQUALS = 4;
	public static final int NOT_EQUALS = 5;
	public static final int BEGINS_WITH = 6;
	public static final int ENDS_WITH = 7;
	public static final int CONTAINS = 8;
	protected static final int LIKE = 9;

	private int operator;
	private FmField field;
	private Object value;
	private boolean isPlaceholder;

	public SearchTerm(FmField field, int operator, Object value, boolean isPlaceholder) {
		if (isPlaceholder && value!=null) throw new IllegalArgumentException("placeholder SearchTerms must use null for value.");
		if ("null".equalsIgnoreCase(String.valueOf(value))) value = null;
		this.field = field;
		this.operator = operator;
		this.value = value;
		this.isPlaceholder = isPlaceholder;
	}

	/** The FmField being searched on. */
	public FmField getField() {
		return field;
	}

	/** The type of search argument for this SearchTerm. */
	public int getOperator() {
		return operator;
	}

	/** The value for this Term, or null if the value is NULL. */
	public Object getValue() { //FIX!! Should this return a String instead? When would it return a non-String value?
		return value;
	}

	/** Whether this Term is a placeHolder in a PreparedStatement. */
	public boolean isPlaceholder() {
		return isPlaceholder;
	}
}
